package com.atilim.cargo.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;

/**
 * 
 * @author 
 *
 */
public class BaseServlet extends HttpServlet {

	

	
	
	public void execute (HttpServletRequest req, HttpServletResponse resp) throws Exception {
		
	}


	/**
	 * 
	 * @param req
	 * @param resp
	 */
	protected void doExecute (HttpServletRequest req, HttpServletResponse resp){
		try {
			execute(req, resp);
		} catch (Exception e) {
			e.printStackTrace();
			JSONObject obj = new JSONObject();
			try {
				obj.put("msg", e.getMessage());
				obj.put("success", false);
				resp.getWriter().write(obj.toString());
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doExecute(req, resp);
	}


	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doExecute(req, resp);
	}

	
	
}
